package com.gimi.cloud.jimi.dao.dao.prod;

import com.gimi.cloud.jimi.dao.common.SqlProvider;
import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParam;
import com.gimi.cloud.jimi.dao.myMapper.core.query.QueryParamProvider;
import com.gimi.cloud.jimi.dto.prod.ProdCategoryDTO;
import com.gimi.cloud.jimi.entity.prod.ProdCategoryEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by lixj on 2017/12/18.
 */
@Mapper
public interface ProdCategoryDao extends MyMapper<ProdCategoryEntity>,BaseDao<ProdCategoryEntity,ProdCategoryDTO> {


    /**
     * 根据ID获取商品品类
     * @return
     * @param parentCatId
     */
    @Select("select t.* from ec_prod_category t where t.prod_cat_id=#{parentCatId}")
    List<ProdCategoryDTO> getCategoryListById(@Param(value = "parentCatId") String parentCatId);
    /**
     * 获取商品三级品类列表
     * @return
     */
    @Select("SELECT * FROM ec_prod_category WHERE cat_grade=3 ")
    List<ProdCategoryDTO> getCategoryList();
    /**
     * 获取所有品类
     * @return
     */
    List<ProdCategoryDTO> getAllProdCategory();
    
    /**
     * 获取商品品类列表(分页)
     * @return
     */
    @SelectProvider(method = "sql",type = SqlProvider.class)
    List<ProdCategoryDTO> queryPage(String sql);

    /**
     * 品类后台页面展示，支持条件查询
     * @param prodCategoryDTO
     * @return
     */
    List<ProdCategoryDTO> queryPageList(ProdCategoryDTO prodCategoryDTO);

    /**
     * 转跳到编辑界面查询
     * @param prodCategoryDTO
     * @return
     */
    ProdCategoryDTO findProdCategoryByProdCatId(ProdCategoryDTO prodCategoryDTO);

    /**
     * 删除品类，逻辑删除/启用
     * @param prodCategoryDTO
     */
    @Update("UPDATE ec_prod_category SET is_delete = #{isDelete} where prod_cat_id=#{prodCatId}")
    void deleteCategory(ProdCategoryDTO prodCategoryDTO);

    /**
     * 根据参数查询出所有的对应商品品类列表
     * @param i
     */
    @Select("select t.* from ec_prod_category t where t.cat_grade=#{i}")
    List<ProdCategoryDTO> searchCategoryListByGrade(int i);

    @SelectProvider(method = "selectCountBySql",type = QueryParamProvider.class)
    String findMaxCatIdByGrade(QueryParam param);

    @Select("select t.* from ec_prod_category t where t.prod_cat_name=#{prodCatName} and t.cat_grade =#{catGrade} and t.prod_cat_id !=#{prodCatId} ")
    List<ProdCategoryDTO> getCategoryListByName(@Param(value = "prodCatName")String prodCatName,@Param(value = "catGrade")Integer catGrade,@Param(value = "prodCatId")String prodCatId);

    @Select("select t.* from ec_prod_category t where t.prod_cat_name=#{prodCatName} and t.cat_grade =#{catGrade} and t.prod_cat_id !=#{prodCatId} ")
    List<ProdCategoryDTO> getCategoryListByNameNew(@Param(value = "prodCatName")String prodCatName, @Param(value = "catGrade")Integer catGrade, @Param(value = "prodCatId")String prodCatId);


    @SelectProvider(type = SqlProvider.class,method = "sql")
    List<ProdCategoryDTO> findByCatIds(String sql);

    @Select("select t.* from ec_prod_category t where t.prod_cat_name=#{prodCatName} and t.cat_grade =#{catGrade} ")
    List<ProdCategoryDTO> getCategoryListByNameForAdd(@Param(value = "prodCatName")String prodCatName,@Param(value = "catGrade")Integer catGrade);

    @Select("select t.* from ec_prod_category t where t.prod_cat_name=#{prodCatName} and t.cat_grade =#{catGrade} ")
    List<ProdCategoryDTO> getCategoryListByNameForAddNew(@Param(value = "prodCatName")String prodCatName,@Param(value = "catGrade")Integer catGrade);

    @Select("SELECT prod_cat_id,prod_cat_name,parent_cat_id,cat_grade,img_url FROM ec_prod_category WHERE parent_cat_id = #{parentCatId};")
    List<ProdCategoryDTO> getCategoryListByParent(@Param(value = "parentCatId") String parentCatId);
}
